﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using QzEbook.BaseView;
using QzEbook.Admin;
using QzEbook.Common;
using QzEbook.AccessObject;

public partial class favorite : CheckPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindData();
    }

    private void BindData()
    {
        userSession = this.Session[SessionManager.LOGINUSER] as SessionUser;
        if (String.IsNullOrEmpty(Request["Bid"]))
        {
            outputXML("没有传递收藏书ID");
            return;
        }
        if (userSession == null)
        {
            outputXML("你还没有登陆");
            return;
        }

        Favorite favoriteAction = new Favorite();
        favoriteAction.BookId = int.Parse(Request["Bid"]);
        favoriteAction.UserId = userSession.Uid;
        if (Request["type"] == "add")
        {
            if (favoriteAction.insert())
            {
                outputXML("收藏成功");
            }
            else
            {
                outputXML("收藏失败");
            }
        }
        else
        {
            if (favoriteAction.delete())
            {
                outputXML("删除成功");
            }
            else
            {
                outputXML("删除失败");
            }
        }
    }


    private void outputXML(String message)
    {
        Response.Clear();
        Response.ContentType = "Text/xml";
        string returnValue = string.Format("<root><return>{0}</return></root>", message);
        Response.Write(returnValue);
        Response.End();
    }

}
